home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
9-Digit Zip Code Directory
/
9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO
/
z4src.zip
/
CLEVENT.CPP
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-06
|
11KB
|
353 lines
//----------------------------------------------------------------------------
// MODULE DESCRIPTION
//
// Module: clevent.cpp
// Title: C++ Class Libraries
// Notice: John M. Weeder
// Copyright (c) 1993. All rights reserved.
// This module contains proprietary information and should be
// treated as confidential.
//
//----------------------------------------------------------------------------
// MAINTENANCE HISTORY
//
// $Workfile$
// $Revision$
// $Author$
// $Date$
// $Log$
//
//----------------------------------------------------------------------------
// MODULE NARRATIVE
//
// This module contains code for the class CL_EVENT.
//
// The code in this module may be written in C++ or C.
//
// This module is portable to:
// DOS 3.X+
// MS Windows 3.X+
// OS/2 2.X+
// OS/2 2.0 PM
//
// The following compilers are supported:
// MSC 6.0A
// MSC/C++ 7.0
// Borland C++ 3.1 for DOS
// Borland C++ 1.0 for OS/2 2.X
//
//----------------------------------------------------------------------------
#include <class.hpp>
//----------------------------------------------------------------------------
// Description: Default constructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_EVENT::CL_EVENT()
{
CL_EVENT::Initialize(CL_INIT_CLASS);
}
//----------------------------------------------------------------------------
// Description: Copy constructor
// Parameters: rccl_event Reference to object to copy.
// Returns:
//----------------------------------------------------------------------------
FN_M CL_EVENT::CL_EVENT(RCCL_EVENT rccl_event)
{
CL_EVENT::Initialize(CL_INIT_CLASS);
*this = rccl_event;
}
//----------------------------------------------------------------------------
// Description: Destructor
// Parameters:
// Returns:
//----------------------------------------------------------------------------
FN_M CL_EVENT::~CL_EVENT()
{
CL_EVENT::Destroy(FALSE);
}
//----------------------------------------------------------------------------
// Description: Destroy object. Free any resources used by object.
// Normally called by destructor.
// Should allow multiple calls from various classes.
// Parameters: fDestroyAll Destroy parents also?
// Default is TRUE.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Destroy(BOOL fDestroyAll)
{
#if OS_OS2
if (fCreated)
{
APIRET rc;
if ((rc = DosCloseEventSem(hev)) != 0)
Error("Problem destroying semaphore (%ld)", (LONG)rc);
fCreated = FALSE;
}
#endif
CL_EVENT::Initialize(CL_INIT_CLASS_VARS);
if (fDestroyAll) // Destroy parent.
CL_EVENT_PARENT::Destroy(fDestroyAll);
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Initialize object.
// Normally called by constructor.
// Should allow multiple calls from various classes.
// Parameters: sInit Initialization code. May be one of the following:
// CL_INIT_CLASS Reset class variables and
// and dynamic allocations for
// this class only.
// CL_INIT_CLASS_VARS Reset class variables for
// this class only.
// CL_INIT_VARS Reset class variables for
// this class only.
// CL_INIT_ALL Initialize class and all
// parent class, including
// dynamic memory allocation.
// Default is CL_INIT_ALL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Initialize(SHORT sInit)
{
if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
CL_EVENT_PARENT::Initialize(sInit);
#if OS_OS2
fCreated = FALSE;
#endif
if (sInit == CL_INIT_CLASS_VARS || sInit == CL_INIT_VARS)
return TRUE;
#if OS_OS2
APIRET rc = DosCreateEventSem(NULL, &hev, 0, 0);
if (rc != 0)
return Error("Problem creating event semaphore (%ld)", (LONG)rc);
fCreated = TRUE;
#endif
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Check if object is in error state.
// IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
// Parameters:
// Returns: TRUE if in error state.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::IsError() const
{
return CL_EVENT_PARENT::IsError();
}
//----------------------------------------------------------------------------
// Description: Check if object is valid
// IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
// Parameters:
// Returns: TRUE if valid
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::IsValid() const
{
return CL_EVENT_PARENT::IsValid();
}
//----------------------------------------------------------------------------
// Description: Assignment operator
// NOTE: Don't copy object into self
// Parameters: rccl_event Reference to right value.
// Returns: Reference to new object.
//----------------------------------------------------------------------------
RCCL_EVENT FN_M CL_EVENT::operator=(RCCL_EVENT rccl_event)
{
if (this != &rccl_event)
{
Invalid("CL_EVENT::operator=");
}
return (RCCL_EVENT)*this;
}
//----------------------------------------------------------------------------
// Description: Post an event semaphore
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Post()
{
#if OS_OS2
APIRET rc = DosPostEventSem(hev);
if (rc != 0)
return Error("Problem posting event semaphore (%ld)", (LONG)rc);
#endif
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Reset an event semaphore
// Parameters:
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Reset()
{
#if OS_OS2
ULONG ulPostCt;
APIRET rc = DosResetEventSem(hev, &ulPostCt);
if (rc != 0)
Error("Problem resetting event semaphore (%ld)", (LONG)rc);
#endif
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Retrieve object from persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Retrieve(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz);
NOTUSED(pcszSub);
Invalid("CL_EVENT::Retrieve");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Store object to persistent storage
// Parameters: pcsz Name of object.
// pcszSub Sub-name of object.
// The first character of the name should be '~'.
// If NULL, no sub name is available.
// Default is NULL
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Store(PCSZ pcsz, PCSZ pcszSub)
{
NOTUSED(pcsz);
NOTUSED(pcszSub);
Invalid("CL_EVENT::Store");
return FALSE;
}
//----------------------------------------------------------------------------
// Description: Wait for an event semaphore to be posted.
// Parameters: ulWait Number of milliseconds to wait.
// If -1l, wait forever
// Default is -1.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
BOOL FN_M CL_EVENT::Wait(ULONG ulWait)
{
#if OS_OS2
# ifndef ERROR_TIMEOUT
# define ERROR_TIMEOUT 640
# define ERROR_INTERRUPT 95
# endif
APIRET rc = DosWaitEventSem(hev, ulWait);
if (rc == ERROR_TIMEOUT)
return TRUE;
if (rc != 0)
return Error("Problem while waiting for event semaphore (%ld)", (LONG)rc);
#else
NOTUSED(ulWait);
#endif
return TRUE;
}
//----------------------------------------------------------------------------
// Description: Print object value to debugging output.
// Parameters: pccl_event Pointer to dynamic object.
// If NULL, static data elements are printed.
// Default is NULL.
// pcsz Name of object.
// If NULL, no name is displayed.
// Default is NULL.
// cLevel Display level.
// Default is zero.
// Returns:
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
VOID FN_M CL_EVENT::Print(PCCL_EVENT pccl_event, PCSZ pcsz, SIZET cLevel)
{
#if COMPILE_TEST
OutputL(cLevel, "CL_EVENT%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
cLevel++;
if (pccl_event)
{
Output(" <%p>\n", pccl_event);
if(!pccl_event->IsError())
{
#if OS_OS2
OutputL(cLevel, "hev = %p\n", pccl_event->hev);
OutputL(cLevel, "fCreated = %ld\n", (LONG)pccl_event->fCreated);
#endif
}
}
else
Output(" <NULL>\n");
CL_EVENT_PARENT::Print((CL_EVENT_PARENT _FAR_ *)pccl_event, pcsz, cLevel);
return ;
#else
NOTUSED(cLevel);
NOTUSED(pccl_event);
NOTUSED(pcsz);
return ;
#endif
}
#endif
//----------------------------------------------------------------------------
// Description: Run standard test suite on object.
// Parameters: sTest Test to run.
// If 0, run default tests.
// Default is 0.
// Returns: TRUE if successful.
//----------------------------------------------------------------------------
#if COMPILE_DEBUG
BOOL FN_M CL_EVENT::Test(SHORT sTest)
{
#if COMPILE_TEST
if (sTest == 1) // Test 1 is always a test of storage
{
CL_EVENT cl_event;
cl_event.Store("CL_EVENT");
cl_event.Retrieve("CL_EVENT");
CL_EVENT::Print(&cl_event);
}
return TRUE;
#else
NOTUSED(sTest);
return TRUE;
#endif
}
#endif
//----------------------------------------------------------------------------
//------------------------------- End of File --------------------------------
//----------------------------------------------------------------------------